package kr.go.nih.biomedi.snptorrent.servlet;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.List;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import kr.go.nih.biomedi.snptorrent.bo.SNP131Name;
import kr.go.nih.biomedi.snptorrent.dao.SNP131Dao;

public class GraphServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public GraphServlet() {
		super();
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String chrom = request.getParameter("chrom");
		int chromStart = Integer.parseInt(request.getParameter("chromStart"));
		int chromEnd = Integer.parseInt(request.getParameter("chromEnd"));
		
		BufferedImage image = new BufferedImage(700, 500, BufferedImage.TYPE_INT_ARGB);
		Graphics2D g = image.createGraphics();
		g.setBackground(Color.WHITE);
		g.setColor(Color.BLACK);
		
		try {
			SNP131Dao snp = new SNP131Dao();
			List<SNP131Name> snpList = (List<SNP131Name>) snp.getSNP131InformationByChromRange("chr1", 33031597, 33041570);
			for (int i = 0; i < 10 ; i++) {
				SNP131Name snpName = (SNP131Name) snpList.get(i);
				g.drawString(snpName.getName(), i * 10, i * 20);
			 }
		} catch (Exception e) {
			e.printStackTrace();
		}
		ServletOutputStream outStream = response.getOutputStream();
		ImageIO.write(image, "png", outStream);
		outStream.close();
	}
}
